package com.itcast.datasource.druid;

import com.itcast.utils.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * 测试 jdbc 工具类
 * 给 account 表添加一条记录
 */
public class druidDemo2 {
    public static void main(String[] args) {

        Connection connection = null;
        PreparedStatement preparedStatement = null;
        try {
            // 获取连接
            connection = JDBCUtil.getConnection();
            // 定义 sql
            String sql = "INSET INTO account VALUES (null,?,?)";
            // 获取执行 sql 对象
            preparedStatement = connection.prepareStatement(sql);
            // 设置值
            preparedStatement.setString(1, "王武");
            preparedStatement.setDouble(2, 3000);
            // 执行 sql
            int count = preparedStatement.executeUpdate();
            System.out.println(count);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 释放资源
            JDBCUtil.close(preparedStatement, connection);
        }

    }
}
